package com.example.demoss.controller;

import com.example.demoss.entity.ResultCountry;
import com.example.demoss.entity.ResultVo;
import com.example.demoss.model.CallResult;
import com.example.demoss.service.TrueService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 黄靖
 * @author 2022-12-12 16:35
 * description:
 **/
@Slf4j
@RestController
@RequestMapping("index")
public class TrueApi {


    @Resource
    private TrueService service;



    @GetMapping("day/{day}")
    public CallResult<ResultVo>  listByDay(@PathVariable(value = "day") int day){

        ResultVo resultVo =  service.getAllDataByOneDay(day);
return CallResult.success(1,"sucess", resultVo);
    }


    @GetMapping("country")
    public CallResult  listByCountry(){
         ArrayList<ResultVo> resultVos = new ArrayList<>();

        for(int i=1;i<=31;i++){
        final ResultVo allDataByOneDay = service.getAllDataByOneDay(i);
    resultVos.add(allDataByOneDay);
        }

       ResultCountry resultVo = service.listByCountry(resultVos) ;

return CallResult.success(1,"sucess",resultVo);

    }

    @GetMapping("season/{season}")
    public CallResult<ResultVo> listAllBySeason(@PathVariable("season") int season){
         List<Integer>  list = new ArrayList();

           switch (season){
               case  1:
               for(int i = 1;i<=10;i++){
                 list.add(i);
               } ;
                   break;

               case 2:
                   for(int i = 11;i<=20;i++){
                       list.add(i);
                   };
                   break;

               case 3:
                   for(int i = 21;i<=31;i++){
                       list.add(i);
                   };
                   break;


           }


        ResultVo resultVo =   service.listBySeason(list,String.valueOf(season));
           list.clear();



        return CallResult.success(1,"sucess", resultVo);


    }


}
